#include<bits/stdc++.h>
using namespace std;
int a[500005],t[5000005];
int  main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        int n,m=-1,s=0;
        cin>>n;
        memset(a,0,sizeof(a));
        memset(t,0,sizeof(t));
        for(int i=1;i<=n;i++){
            cin>>a[i];
            t[a[i]]++;
            m=max(m,a[i]);
        }
        for(int i=m;i>=1;i--){
            if(t[i]>1){
                s=s+i;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}
